package com.bwie.controller;

import com.bwie.domain.Food;
import com.bwie.service.IFoodService;
import com.bwie.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Ms.发发
 * @ClassName PinController
 * @Date 2024/12/18 8:41
 * @Description
 **/
@Slf4j
@RestController
@RequestMapping("/pin")
public class PinController {

    @Autowired
    private IFoodService foodService;


    /****
     * @Author Ms.发发
     * @Description 定义post请求（10分）  我要拼团
     * @param food   食物
     * @Date 2024/12/18 8:55
     * @return {@link R}
     */
    @PostMapping
    public R pin(@Validated @RequestBody Food food){
        int insertCount = foodService.insert(food);
        log.info("===拼团成功 insertCount={}",insertCount);
        return R.OK(insertCount);
    }

    /****
     * @Author Ms.发发
     * @Description   拼团数据
     * @Date 2024/12/18 8:59
     * @return {@link R}
     */
    @GetMapping
    public R selectAll(){
        List<Food> foods = foodService.selectAll();
        log.info("==拼团数据 data={}",foods);
        return R.OK(foods);
    }

}
